/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * File Name     : vroce_cfg_base.h
 * Description   : common infos for kernel module and user module
 * History       : create file & add functions
 * 1.Date        : 2023-2-11
 * Author        : HW
 * Modification  : Created file
 */

#ifndef VROCE_CFG_BASE_H
#define VROCE_CFG_BASE_H

#define VROCE_VERSION    GLOBAL_VERSION_STR
#define VROCE_CFG_FAMILY_NAME       "VROCE_CFG"
#define VROCE_CFG_FAMILY_VERSION    0x1
#define RACL_GROUP_MSG_MAX  10
#define RACL_IPPAIR_NUM_MAX  (100000)
#define RACL_QPC_XID_MIN 2
#define RACL_DUMP_INDEX_MIN 0
#define RACL_QPC_XID_OFFSET (RACL_QPC_XID_MIN - RACL_DUMP_INDEX_MIN)
#define RACL_QPC_XID_MAX (RACL_QPC_XID_MIN + RACL_IPPAIR_NUM_MAX)
#define RACL_DUMP_COUNT_MAX 500
#define RACL_IPPAIR_MSG_MAX  10
#define DEV_NAME_LEN 16
#define BDF_STR_LEN 13
#define ETH_ADDR_LEN 6
#define ETH_STR_LEN 17
#define PROBE_SAVE_PATH_LEN 64
#define PROBE_INPUT_OPCODE_LEN 64
#define PROBE_PORT_MIN 1
#define PROBE_PORT_MAX 65535
#define PROBE_DEFAULT_CAP_COUNT 8000
#define PROBE_QPN_MIN 0
#define PROBE_QPN_MAX 65535
#define IPV4_LEN 4
#define IPV6_LEN 8
#define IP_LEN 4
#define BYTE_MASK 0xFF
#define ROCE_DEV_NUM_MAX 121
#define ROCE_DEV_BASE_ID_MAX 32
#define ROCE_FUNC_ID_MAX 4096
#define VF_ID_MAX 255
#define VLAN_ID_MAX ((1 << 12) - 1)
#define WND_RST_RATIO_MAX ((1 << 4) - 1)
#define WND_RST_TMOUT_MAX ((1 << 4) - 1)
#define GROUP_ID_MAX 2
#define DSCP_MAX 63
#define PRIORITY_MAX 7
#define BW_PROPORTION_SUM 10
#define PFC_NUM 8
#define IP_STR_LEN 64
#define ID_STR_LEN 16
#define VROCE_DATA_DIR "/opt/hivroce/"
#define UNUSED __attribute__((__unused__))
#define RACL_LIST_PATH (VROCE_DATA_DIR"roceacl-list_")
#define PAIR_LIST_PATH (VROCE_DATA_DIR"roceacl-list-ip_")
#define RACL_STORE_PATH (VROCE_DATA_DIR"roceacl-list-store")
#define PAIR_STORE_PATH (VROCE_DATA_DIR"roceacl-list-ip-store")
#define UUID_STORE_PATH (VROCE_DATA_DIR"roceacl-uuid-store")
#define FOPEN_MODE 0640
#define ARP_ENTRY_MAX 8192
#define PCMD_STR_MAX 200
#define QP_BASE_STRIDE 65536

#define VROCE_ROUTE_FILE "/proc/net/route"
#define MAX_LINE_LEN 512

#define VF_ARGS_INCLUDE_BDF      (1)
#define VF_ARGS_INCLUDE_RACL_ID  (1 << 1)
#define VF_ARGS_INCLUDE_VTEP_IP  (1 << 2)
#define VF_ARGS_INCLUDE_VTEP_MAC (1 << 3)
#define VF_ARGS_INCLUDE_DSCP     (1 << 4)
#define VF_ARGS_INCLUDE_DEFAULT_GWMAC  (1 << 6)
#define VF_ARGS_INCLUDE_VTEP_IPV6  (1 << 7)
#define VF_ARGS_INCLUDE_REQUIRED VF_ARGS_INCLUDE_BDF

#define DSCP_ARGS_INCLUDE_ID     (1)
#define DSCP_ARGS_INCLUDE_BW_PPT (1 << 1)
#define DSCP_ARGS_INCLUDE_PFC    (1 << 2)
#define DSCP_ARGS_INCLUDE_TYPE   (1 << 3)
#define DSCP_ARGS_INCLUDE_DSCP   (1 << 4)
#define DSCP_ARGS_INCLUDE_PRIORITY   (1 << 5)
#define DSCP_ARGS_TYPE_REQUIRED  (DSCP_ARGS_INCLUDE_ID | DSCP_ARGS_INCLUDE_DSCP | DSCP_ARGS_INCLUDE_TYPE)
#define DSCP_ARGS_SET_REQUIRED   (DSCP_ARGS_INCLUDE_ID | DSCP_ARGS_INCLUDE_BW_PPT | \
                                  DSCP_ARGS_INCLUDE_PRIORITY | DSCP_ARGS_INCLUDE_PFC)

#define GLOBAL_ARGS_INCLUDE_VLAN_ID  (1 << 5)
#define GLOBAL_ARGS_INCLUDE_PRECISION  (1 << 6)

#define CC_PARAM_ARGS_INCLUDE_WND_RST_RATIO  (1)
#define CC_PARAM_ARGS_INCLUDE_WND_RST_TMOUT  (1 << 1)

#define ROCEACL_LIST_ARGS_INCLUDE_ID      (1)
#define ROCEACL_LIST_IP_ARGS_INCLUDE_VIP  (1 << 1)
#define ROCEACL_LIST_ARGS_INCLUDE_JSON    (1 << 2)

#define PROBE_ARGS_INCLUDE_VF       (1)
#define PROBE_ARGS_INCLUDE_COUNT    (1 << 1)
#define PROBE_ARGS_INCLUDE_FILE     (1 << 2)
#define PROBE_ARGS_INCLUDE_DST_QPN  (1 << 3)
#define PROBE_ARGS_INCLUDE_SIP      (1 << 4)
#define PROBE_ARGS_INCLUDE_DIP      (1 << 5)
#define PROBE_ARGS_INCLUDE_SPORT    (1 << 6)
#define PROBE_ARGS_INCLUDE_OPCODE   (1 << 7)
#define PROBE_ARGS_START_REQUIRED   (PROBE_ARGS_INCLUDE_VF | PROBE_ARGS_INCLUDE_FILE)

#define PROBE_ADDR_NUM 255
#define PROBE_BLOCK_SIZE 256
#define PROBE_PKT_CNT 0x39ff
#define PROBE_PKT_LOSS_CNT 1

#define USERNAME_LEN        32
#define FILE_VROCE_PRE_LEN   32
#define FILE_VROCE_LEN   (FILE_VROCE_PRE_LEN + USERNAME_LEN)

#define VROCE_GET_OFFSET_TYPE(base, offset, type) ((type)(((char *)(base)) + (offset)))
#define VROCE_GET_OFFSET_VALUE(base, offset, type) (*((type*)(((char *)(base)) + (offset))))

#define VROCE_HT_KEY0_LEN 2
#define VROCE_HT_KEY_RACL_ID_LEN 4
#define VROCE_HT_KEY_VIP_LEN 16
#define VROCE_HT_KEY_RSVD_LEN 32

#define VROCE_HT_VALUE_VNI_LEN 4
#define VROCE_HT_VALUE_VTEP_IP_LEN 16
#define VROCE_HT_VALUE_VF_ID_LEN 2
#define VROCE_HT_VALUE_MODE_LEN 1
#define VROCE_HT_VALUE_IP_TYPE_LEN 1
#define VROCE_HT_VALUE_GWMAC_LEN 6
#define VROCE_HT_VALUE_VMMAC_LEN 6
#define VROCE_HT_VALUE_RSVD_LEN 2

#define VROCE_HT_KEY_IN_QPC_OFFSET 10
#define VROCE_HT_VALUE_IN_QPC_OFFSET 64

#define VROCE_RACL_ID_IN_QPC_OFFSET (VROCE_HT_KEY_IN_QPC_OFFSET + VROCE_HT_KEY0_LEN)
#define VROCE_VIP_IN_QPC_OFFSET (VROCE_RACL_ID_IN_QPC_OFFSET + VROCE_HT_KEY_RACL_ID_LEN)
#define VROCE_VIP1_IN_QPC_OFFSET (VROCE_VIP_IN_QPC_OFFSET + 4)
#define VROCE_VIP2_IN_QPC_OFFSET (VROCE_VIP1_IN_QPC_OFFSET + 4)
#define VROCE_VIP3_IN_QPC_OFFSET (VROCE_VIP2_IN_QPC_OFFSET + 4)

#define VROCE_VNI_IN_QPC_OFFSET VROCE_HT_VALUE_IN_QPC_OFFSET
#define VROCE_VTEP_IP_IN_QPC_OFFSET (VROCE_VNI_IN_QPC_OFFSET + VROCE_HT_VALUE_VNI_LEN)
#define VROCE_VTEP_IP1_IN_QPC_OFFSET (VROCE_VTEP_IP_IN_QPC_OFFSET + 4)
#define VROCE_VTEP_IP2_IN_QPC_OFFSET (VROCE_VTEP_IP1_IN_QPC_OFFSET + 4)
#define VROCE_VTEP_IP3_IN_QPC_OFFSET (VROCE_VTEP_IP2_IN_QPC_OFFSET + 4)
#define VROCE_VF_ID_IN_QPC_OFFSET (VROCE_VTEP_IP_IN_QPC_OFFSET + VROCE_HT_VALUE_VTEP_IP_LEN)
#define VROCE_MODE_IN_QPC_OFFSET (VROCE_VF_ID_IN_QPC_OFFSET + VROCE_HT_VALUE_VF_ID_LEN)
#define VROCE_IP_TYPE_IN_QPC_OFFSET (VROCE_MODE_IN_QPC_OFFSET + VROCE_HT_VALUE_MODE_LEN)
#define VROCE_GWMAC_IN_QPC_OFFSET (VROCE_IP_TYPE_IN_QPC_OFFSET +VROCE_HT_VALUE_IP_TYPE_LEN)
#define VROCE_VMMAC_IN_QPC_OFFSET (VROCE_GWMAC_IN_QPC_OFFSET + VROCE_HT_VALUE_GWMAC_LEN)

#define ROCEMIG_IPV6_ADDR_LEN 16
#define ROCEMIG_ENTRY_MAX_COUNT 64

#ifdef LLT_TEST
#define STATIC
#else
#define STATIC static
#endif

enum vroce_probe_block_idx {
    PROBE_BLOCK_IDX_0 = 0,
    PROBE_BLOCK_IDX_1,
    PROBE_BLOCK_IDX_2,
    PROBE_BLOCK_IDX_3,
    PROBE_BLOCK_IDX_4,
    PROBE_BLOCK_IDX_5,
    PROBE_BLOCK_IDX_6,
    PROBE_BLOCK_IDX_7,
    PROBE_BLOCK_IDX_MAX
};

enum vroce_probe_shift {
    PROBE_SHIFT_0 = 4,
    PROBE_SHIFT_1,
    PROBE_SHIFT_2,
    PROBE_SHIFT_3,
    PROBE_SHIFT_4,
    PROBE_SHIFT_5,
    PROBE_SHIFT_6,
    PROBE_SHIFT_7
};

enum vroce_probe_block_num {
    PROBE_BLOCK_NUM_0 = 16,
    PROBE_BLOCK_NUM_1 = 32,
    PROBE_BLOCK_NUM_2 = 64,
    PROBE_BLOCK_NUM_3 = 128,
    PROBE_BLOCK_NUM_4 = 256,
    PROBE_BLOCK_NUM_5 = 512,
    PROBE_BLOCK_NUM_6 = 1024,
    PROBE_BLOCK_NUM_7 = 2048
};

// microcode use 128 bits to store addrs, one block can store two u64 addrs
enum vroce_probe_pa_num {
    PROBE_PA_0 = 0,
    PROBE_PA_1,
    PROBE_PA_NUM
};

enum vroce_probe_addr_type {
    PROBE_ADDR_V = 0,
    PROBE_ADDR_P,
    PROBE_ADDR_TYPE_NUM
};

// add cmd enum here
enum vroce_cfg_ops_racl {
    VROCE_CFG_OPS_RACL_CREATE,
    VROCE_CFG_OPS_RACL_LIST,
    VROCE_CFG_OPS_RACL_DESTROY,
    VROCE_CFG_OPS_RACL_ADD_IP,
    VROCE_CFG_OPS_RACL_LIST_IP,
    VROCE_CFG_OPS_RACL_DEL_IP,
    VROCE_CFG_OPS_RACL_IP_GETBULK,
    VROCE_CFG_OPS_RACL_GET_ENTRY_NUM,
    VROCE_CFG_OPS_RACL_MAX
};

enum vroce_cfg_ops_vrdma {
    VROCE_CFG_OPS_VF_ADD,
    VROCE_CFG_OPS_VF_SET,
    VROCE_CFG_OPS_VF_DEL,
    VROCE_CFG_OPS_VF_SHOW,
    VROCE_CFG_OPS_VF_LIST,
    VROCE_CFG_OPS_VF_MAX
};

enum vroce_cfg_ops_statics {
    VROCE_CFG_OPS_STATICS_VF,
    VROCE_CFG_OPS_STATICS_GLOBAL,
    VROCE_CFG_OPS_STATICS_MAX
};

enum vroce_cfg_ops_dscp {
    VROCE_CFG_OPS_DSCP_ADD,
    VROCE_CFG_OPS_DSCP_CLEAN,
    VROCE_CFG_OPS_DSCP_SHOW,
    VROCE_CFG_OPS_DSCP_SET,
    VROCE_CFG_OPS_DSCP_DEL,
    VROCE_CFG_OPS_DSCP_MAX
};

enum vroce_cfg_ops_global {
    VROCE_CFG_OPS_GLOBAL_SET,
    VROCE_CFG_OPS_GLOBAL_SHOW,
    VROCE_CFG_OPS_GLOBAL_VERSION,
    VROCE_CFG_OPS_GLOBAL_MAX
};

enum vroce_cfg_ops_icq_threshold {
    VROCE_CFG_OPS_ICQ_THRESHOLD_SET,
    VROCE_CFG_OPS_ICQ_THRESHOLD_SHOW,
    VROCE_CFG_OPS_ICQ_THRESHOLD_MAX
};

enum vroce_cfg_ops_feature {
    VROCE_CFG_OPS_FEATURE_SHOW,
    VROCE_CFG_OPS_FEATURE_MAX
};

enum vroce_cfg_ops_cc_param {
    VROCE_CFG_OPS_CC_PARAM_SET,
    VROCE_CFG_OPS_CC_PARAM_GET,
    VROCE_CFG_OPS_CC_PARAM_MAX
};

enum vroce_cfg_ops_probe {
    VROCE_CFG_OPS_PROBE_START,
    VROCE_CFG_OPS_PROBE_STOP,
    VROCE_CFG_OPS_PROBE_SET,
    VROCE_CFG_OPS_PROBE_MAX
};

enum vroce_cfg_ops_mig_forward {
    VROCE_CFG_OPS_MIG_ADD_ENTRY,
    VROCE_CFG_OPS_MIG_DEL_ENTRY,
    VROCE_CFG_OPS_MIG_DUMP_ENTRY,
    VROCE_CFG_OPS_MIG_DUMP_ALL_ENTRY,
    VROCE_CFG_OPS_MIG_MAX
};

enum vroce_cfg_cmd_type {
    VROCE_CFG_CMD_RACL,
    VROCE_CFG_CMD_VF,
    VROCE_CFG_CMD_DSCP,
    VROCE_CFG_CMD_GLOBAL,
    VROCE_CFG_CMD_PROBE,
    VROCE_CFG_CMD_STATICS,
    VROCE_CFG_CMD_MIG_FORWARD,
    VROCE_CFG_CMD_ICQ_THRESHOLD,
    VROCE_CFG_CMD_FEATURE,
    VROCE_CFG_CMD_MAX
};

enum vroce_cfg_attr {
    VROCE_CFG_ATTR_S32,
    VROCE_CFG_ATTR_S64,
    VROCE_CFG_ATTR_STRING,
    VROCE_CFG_ATTR_UNSPEC,
    VROCE_CFG_ATTR_MAX
};

enum vroce_cfg_error {
    VC_ERROR_OK = 0,
    VC_ERROR_PARSE,
    VC_ERROR_SOCKET,
    VC_ERROR_FAMILY,
    VC_ERROR_CMD_UNKNOWN,
    VC_ERROR_OPS_UNKNOWN,
    VC_ERROR_ATTR_MISS,
    VC_ERROR_KZALLOC,
    VC_ERROR_MEMCPY,
    VC_ERROR_MEMSET,
    VC_ERROR_SNPS,
    VC_ERROR_GNM_NEW,
    VC_ERROR_GNM_PUT,
    VC_ERROR_NLA_PUT,
    VC_ERROR_GNM_REP,
    VC_ERROR_RACL_EXIST,
    VC_ERROR_RACL_NONEXIST,
    VC_ERROR_RACL_NORM,
    VC_ERROR_RACL_IP_NORM,
    VC_ERROR_RACL_ENTRY_EXIST,
    VC_ERROR_RACL_ENTRY_NONEXIST,
    VC_ERROR_RACL_NUM_INCOMPLETE,
    VC_ERROR_VF_NORM,
    VC_ERROR_VF_EXIST,
    VC_ERROR_VF_NONEXIST,
    VC_ERROR_VF_NOTSUPPORT,
    VC_ERROR_DEV_EMPTY,
    VC_ERROR_DSCP_EXIST,
    VC_ERROR_DSCP_NONEXIST,
    VC_ERROR_UPMSG_ERR,
    VC_ERROR_UP_LT_WRITE,
    VC_ERROR_UP_LT_READ,
    VC_ERROR_FILE_OPEN,
    VC_ERROR_FILE_WRITE,
    VC_ERROR_FILE_READ,
    VC_ERROR_PROBE_REENTRY,
    VC_ERROR_SET_FLIE_NAME,
    VC_ERROR_GET_NAME,
    VC_ERROR_STRCOPY,
    VC_ERROR_STRCAT,
    VC_ERROR_RENAME,
    VC_ERROR_MALLOC,
    VC_ERROR_PARA,
    VC_ERROR_IPSU,
    VC_ERROR_OTHER,
    VC_ERROR_VROCE_FUNC_INVALID,
    VC_ERROR_VROCE_COS_NUM_INVALID,
    VC_ERROR_VROCE_DSCP_VALUE_INVALID,
    VC_ERROR_DUMP_START_INDEX_INVALID,
    VC_ERROR_DUMP_MAX_COUNT_INVALID,
    VC_ERROR_FILENAME_INVALID,
    VC_ERROR_MIGENTRY_EXIST,
    VC_ERROR_MIGENTRY_NONEXIST,
    VC_ERROR_MIGENTRY_NORM,
    VC_ERROR_MIGENTRY_GET_KEY,
    VC_ERROR_MAX
};

enum ip_v4_index {
    IP_V4_P0,
    IP_V4_P1,
    IP_V4_P2,
    IP_V4_P3
};

enum mac_index {
    MAC_P0,
    MAC_P1,
    MAC_P2,
    MAC_P3,
    MAC_P4,
    MAC_P5,
};

enum ip_index {
    IP_INDEX_0 = 0,
    IP_INDEX_1,
    IP_INDEX_2,
    IP_INDEX_3,
    IP_INDEX_4,
    IP_INDEX_5,
    IP_INDEX_6,
    IP_INDEX_7,
};

#endif
